/*
 * ConfigurationManagerDialog.h
 *
 *  Created on: Oct 28, 2012
 *      Author: johnny
 */

#ifndef CONFIGURATIONMANAGERDIALOG_H_
#define CONFIGURATIONMANAGERDIALOG_H_

#include <iostream>
#include <boost/shared_ptr.hpp>

#include <QWidget>
#include <QLabel>
#include <QStackedWidget>
#include <QVBoxLayout>
#include <QPropertyAnimation>

#include "BaseUI.h"
#include "MOSelectionWidget.h"
#include "GraphNode.h"
#include "MovementHandler.h"
#include "resources.h"

#include "../MeasurementObject.h"

#define SPACER  10

namespace ui {

class ConfigurationManagerDialog: public BaseUI {
    Q_OBJECT

    static unsigned short ANIMATION_DURATION;

    QStackedWidget      *stackedWidget;
    QWidget             *pageMOSelect,
                        *pageGraph,
                        *mainWidget,
                        *unusedWidget;
    QLabel              *lblDetails;
    QPropertyAnimation  *animation;

    MOSelectionWidget       *moSelectWidget;

    std::list<GraphNode*>   graphNodes;

    MovementHandler         *moveHandler;

    QRect   devicesRect,
            processorsRect,
            visualizationsRect;

    bool parentAnimating;
    int mainWidgetWidth, mainWidgetHeight;
    int minX, minY, maxX, maxY;
    std::map<int, GraphNode*> indexedNodes;
    bool isSetUp;

    void clearNodes();

private slots:
    void onMOSelectOK();
    void onMOSelectCancel();
    void onGraphAnimOut();

public:
    ConfigurationManagerDialog(QWidget*);
    ~ConfigurationManagerDialog();

    bool nodesMappedOk;
    bool linesDrawn;

    bool setup();

    void clearDetails();
    void displayDetails();
    void autoArrangeMOs(bool = true);
    void mapNodes();
    void drawLines();
    void markSelected(QWidget*);
    std::list<GraphNode*>& nodes();

public slots:
    void onAddMo();
    void onRemoveMo();
    void onRefresh();
};

} /* namespace ui */

#endif /* CONFIGURATIONMANAGERDIALOG_H_ */
